home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Utilities / Winter Shell 1.0d2 / Source / Libraries / LongRectangleLib / LongRectangleLib.c next >
Encoding:
C/C++ Source or Header  |  1993-12-17  |  1.1 KB  |  53 lines  |  [TEXT/KAHL]

  1. /* rectangles using long integers instead of short integers
  2.     93/12/17 aih created */
  3.  
  4. #include <limits.h>
  5. #include "LongRectangleLib.h"
  6. #include "RectangleLib.h"
  7.  
  8. #define ShortValid(n) (SHRT_MIN <= (n) && (n) <= SHRT_MAX)
  9.  
  10. Boolean LRectValid(const LRectType *r)
  11. {
  12.     return(r->top <= r->bottom && r->left <= r->right);
  13. }
  14.  
  15. void LRectToRect(const LRectType *lr, Rect *r)
  16. {
  17.     require(LRectValid(lr));
  18.     require(ShortValid(lr->top) && ShortValid(lr->left));
  19.     require(ShortValid(lr->bottom) && ShortValid(lr->right));
  20.     r->top = lr->top; r->left = lr->left;
  21.     r->bottom = lr->bottom; r->right = lr->right;
  22.     ensure(RectValid(r));
  23. }
  24.  
  25. void LRectFromRect(LRectType *lr, const Rect *r)
  26. {
  27.     require(RectValid(r));
  28.     lr->top = r->top; lr->left = r->left;
  29.     lr->bottom = r->bottom; lr->right = r->right;
  30.     ensure(LRectValid(lr));    
  31. }
  32.  
  33. void LRectOffset(LRectType *r, long h, long v)
  34. {
  35.     require(LRectValid(r));
  36.     r->top += v; r->left += h;
  37.     r->bottom += v; r->right += h;
  38.     ensure(LRectValid(r));    
  39. }
  40.     
  41. long LRectWidth(const LRectType *r)
  42. {
  43.     require(LRectValid(r));
  44.     return(r->right - r->left);
  45. }
  46.  
  47. long LRectHeight(const LRectType *r)
  48. {
  49.     require(LRectValid(r));
  50.     return(r->bottom - r->top);
  51. }
  52.  
  53.